<!DOCTYPE html>
<!-- 
参考： https://blog.csdn.net/weixin_44616652/article/details/107941714
https://blog.csdn.net/qq_22267353/article/details/81233263
https://blog.csdn.net/qq_41164209/article/details/78693683 -->

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,user-scalable=no" />

    <meta
      name="viewport"
      content="initial-scale=1, maximum-scale=1,user-scalable=no"
    />
    <title>不依赖地图服务创建FeatureLayer图层</title>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/3.34/dijit/themes/nihilo/nihilo.css"
    />
    <link
      rel="stylesheet"
      href="https://js.arcgis.com/3.34/esri/css/esri.css"
    />
    <!-- <link
      rel="stylesheet"
      href="http://10.181.12.6:9080/library/3.31/3.31/esri/css/esri.css"
    />
    <link
      rel="stylesheet"
      type="text/css"
      href="http://10.181.12.6:9080/library/3.31/3.31/dijit/themes/tundra/tundra.css"
    /> -->
    <style>
      html,
      body,
      #mainWindow {
        font-family: sans-serif;
        height: 100%;
        width: 100%;
      }
      html,
      body {
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
      }
    </style>

    <script src="https://js.arcgis.com/3.34/"></script>
    <script>
      var map, toolbar, symbol, geomTask

      require([
        "esri/map",
        "esri/SpatialReference",
        "esri/layers/FeatureLayer",
        "esri/geometry/Point",
        "esri/tasks/FeatureSet",
        "esri/graphic",
        "esri/symbols/SimpleMarkerSymbol",
        "dojo/domReady!",
      ], function (
        Map,
        SpatialReference,
        FeatureLayer,
        Point,
        FeatureSet,
        Graphic,
        SimpleMarkerSymbol
      ) {
        map = new Map("map", {
          center: [116.943089, 36.643737],
          zoom: 12,
          logo: false, //logo
          slider: true, //缩小按钮
          opacity: 0.4, // 透明度 默认0.5
          basemap: "osm", // 浅色
        })

        var spatialReference = new SpatialReference(4326)

        var pointArr = [
          new Point(116.94431351934418, 36.642791191513744, spatialReference),
          new Point(116.94313181636085, 36.644263733181496, spatialReference),
          new Point(116.94323946773243, 36.644333923319806, spatialReference),
          new Point(116.94214699103674, 36.64316768441554, spatialReference),
          new Point(116.94173145496477, 36.643359669286696, spatialReference),
          new Point(116.94251530866333, 36.644235392555245, spatialReference),
        ]

        var features = []
        const pointSymbol = new SimpleMarkerSymbol()
        for (var i = 0; i < pointArr.length; i++) {
          var graphics = new Graphic(pointArr[i], pointSymbol, {
            OBJECTID: i,
            LON: pointArr[i].x,
            LAT: pointArr[i].y,
          })
          features.push(graphics)
        }

        var fields = [
          { name: "OBJECTID", type: "esriFieldTypeOID", alias: "OBJECTID" },
          { name: "LON", type: "esriFieldTypeDouble", alias: "LON" },
          { name: "LAT", type: "esriFieldTypeDouble", alias: "LAT" },
        ]

        var featureSetJson = {
          displayFieldName: "",
          geometryType: "esriGeometryPoint",
          fieldAliases: {
            OBJECTID: "OBJECTID",
            LON: "LON",
            LAT: "LAT",
          },
          fields: fields,
          spatialReference: spatialReference,
          features: features,
        }
        var featuresSet = new FeatureSet(featureSetJson)

        var layerDefinition = {
          geometryType: "esriGeometryPoint",
          fields: fields,
        }

        var featureCollection = {
          layerDefinition: layerDefinition,
          featureSet: featuresSet,
        }

        var featureLayer = new FeatureLayer(featureCollection)
        map.addLayer(featureLayer)
      })
    </script>
  </head>
  <body class="nihilo">
    <div id="map"></div>
  </body>
</html>
